package com.xinghou.platform.dao.main.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.xinghou.platform.dao.bases.JdbcTemplate;
import com.xinghou.platform.dao.bases.database.CustomerContextHolder;
import com.xinghou.platform.model.main.Attachment;

/**
 * 
 * @author wzk
 *
 */
@Repository
public class AttachmentDAOImpl  {/*
	@Resource
	private JdbcTemplate jdbcTemplate;
	
	@Override
	public Attachment getAttachmentById(Integer Id) throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql = "SELECT Attach_id, File_uri, Cite_id, Cite_type, Create_time FROM attachment WHERE Attach_id = ?";
		Attachment attachment = jdbcTemplate.queryForObject(sql, new Object[] { Id }, new AttachmentMapper());
		CustomerContextHolder.clearCustomerType();
		return attachment;
	}

	@Override
	public int updateAttachment(Attachment attachment)
			throws DataAccessException {
		StringBuffer strSQL = new StringBuffer(
				"UPDATE attachment SET File_uri=?, Cite_id=?, Cite_type=?, Create_time=? WHERE Attach_id=?"	
				);
		Object[] params = {attachment.getFileUri(),attachment.getCiteId(),attachment.getCiteType(),
				attachment.getCreateTime(),attachment.getAttachId()
		};
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
		int ret = jdbcTemplate.update(strSQL.toString(),params);
		CustomerContextHolder.clearCustomerType();
		return ret;
	}

	@Override
	public int saveAttachment(Attachment attachment) throws DataAccessException {
		StringBuffer strSQL = new StringBuffer(
				"INSERT INTO attachment (File_uri,Cite_id,Cite_type,Create_time) VALUES (?,?,?,?);"
				);
		Object[] params = {attachment.getFileUri(),attachment.getCiteId(),attachment.getCiteType(),attachment.getCreateTime()
		};
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
		int ret =jdbcTemplate.save(strSQL.toString(),params);
		CustomerContextHolder.clearCustomerType();
		return ret;
	}

	private static final class AttachmentMapper implements RowMapper<Attachment> {
		public Attachment mapRow(ResultSet rs, int rowNum) throws SQLException {
			Attachment attachment = new Attachment();
			attachment.setAttachId(rs.getInt("Attach_id"));
			attachment.setFileUri(rs.getString("File_uri"));
			attachment.setCiteId(rs.getInt("Cite_id"));
			attachment.setCiteType(rs.getShort("Cite_type"));
			attachment.setCreateTime(rs.getTimestamp("Create_time"));
			return attachment;
		}
	}*/


}
